/*This exercise is to understand the idea of subclasses and superclasses in java. This is also called inheritance in general. 
The idea is to reuse an existing class's code in the subclass.*/

//Create a class called Account
	
class Account
{
//a private member called balance of type long
	long balance;

	Account(long x)
	{
	balance = x;
	//double balance1 = (long)balance;
	}

//a public method called deposit(long amount) that will add amount to the balance.
	long deposit(long amount)
	{
	//double amount1 = (long) amount;
	balance = amount+balance;
	return balance;
	}

//a public method called withdraw(long amount) that will subtract amount from the balance.

	long withdraw(long amount)
	{
	//long amount1 = (double) amount;
//To make sure programmatically that amount is not greater than balance in case of withdraw.
	if (amount>balance)
	System.out.println("Withdrawl is not possible");
	else	
	balance = balance - amount;
	return balance;
	}
}

//Create another class called SavingsAccount (subclass) that 'extends' from the Account class(superclass) 
class SavingsAccount extends Account
{
	double interest;
	SavingsAccount(long x)
	{
	super (x);

//add a private member called interest and initialize it with 3.5

	interest = 3.5;
	}

//method called add_interest() and write the code to add the interest to the balance.
	double add_interest()
	{
	double balance1 = (long)balance;
	balance1 = balance1 + ((interest*balance1)/100)/12;
return balance1;
	}

//method to display the balance.
	void display_balance()
	{
double balance1 = add_interest();
	System.out.println("Balance is:" +balance1);
	}
}

//created the main method
//an instance of the subclass is created with initial balance 20000

class Phani
{
	public static void main (String args [ ])
	{
	long dbalance,wbalance;
	SavingsAccount a1 = new SavingsAccount(20000L);
	//Account a1 = new Account(20000L);
	dbalance = a1.deposit(500L);
	System.out.println("Balance is: "+dbalance);
	wbalance	 = a1.withdraw(3000L);
	System.out.println("Balance is: "+wbalance);
a1.add_interest();
a1.display_balance();
}
}
